
/*!	brief Application is the Main class of our well ... application.	
 * 	It keep a trace off every entities and update them every fixed time delta
 */
Application=function (){}

/****************************/
/*		Static				*/
/****************************/

	/****************************/
	/*		Properties			*/
	/****************************/
	
		Application.Canvas;		/*!<Store a reference to the HTML5 node "Canvas", wich is the actual window where we draw our graphics	*/
		
		Application.ClearColor	=	new Vec4(0.7,0.7,0.7,1.0);	/*!< Color used to clear the scene when refreshing it	*/
		
		/****************************/
		/*		Methods				*/
		/****************************/
		
		/*	/brief Init a WebGL application from a string reference a valid HTML canvas node	*/
			Application.Init	=	function(CanvasId)
			{
				Application.Canvas=document.getElementById(CanvasId);
				gl = Application.Canvas.getContext("experimental-webgl");
				
				Mouse.Init();
				
				g_Image = new Texture();
				g_Image.LoadTexture("board.png");
				
				GLSLProgram.New("Default", new Shader("fragment"), new Shader("vertex"));
				
				
				Application.InitWebGLFlags();
			
				BufferObject.InitBuffers();
				
				View.New(Entity.New());
				Entity.Last().AddView(View.Default);
				Mouse.MouseDragHandlers.push(new Method( View.Default, View.Default.Move));
			}

			Application.InitWebGLFlags	=	function()
			{
				gl.viewportWidth = Application.Canvas.width;
				gl.viewportHeight = Application.Canvas.height;
				
				gl.clearColor(Application.ClearColor.x, Application.ClearColor.y, Application.ClearColor.z, Application.ClearColor.w);
				
				gl.enable(gl.DEPTH_TEST);
				gl.disable(gl.CULL_FACE);	//	Disable Cull face tell opengl to draw face in 2 sides	*/
				
				gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
				gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
			}
			
			/*	brief The Update function refresh all Entities in the scene	*/
			Application.Update = function()
			{
				 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
				 Mouse.Update();
				for(var i=0; i< Entity.Entities.length; i++)
				{
					Entity.Entities[i].Display();
				}
			}